/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package matching.path;

import java.util.LinkedList;
import java.util.Set;
import java.util.Stack;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLDescription;
import org.semanticweb.owl.model.OWLOntology;

/**
 *
 * @author livia
 */
public class Path {

    private OWLOntology onto;
    private LinkedList<PairOfPath> path;
    private Stack<OWLClass> classes;
    private OWLClass source;

    public Path(OWLOntology onto, OWLClass src) {
        this.onto = onto;
        this.path = new LinkedList<PairOfPath>();
        this.source = src;
        classes = new Stack<OWLClass>();
        classes.push(src);
    }

 /*  public boolean verifier(SubsumptionPair n){
        Set<OWLDescription> set = target.getSuperClasses(onto);
        if(set.contains(n.getFrom()))return true;
        return false;
   }

   public boolean verifier(PropertyPair n){
        Set<OWLDescription> dom = n.getProperty().getDomains(onto);
        Set<OWLDescription> ran = n.getProperty().getRanges(onto);
        if(dom.contains(n.getFrom())&&ran.contains(target))return true;
        return false;
   }*/

   public void addNode(PairOfPath n){
        path.addLast(n);
        classes.push( n.getTo());
   }

   public LinkedList<PairOfPath> getNodes(){
       return path;
   }

    public void removeLastNode(){
        //if(verifier(n))
        path.removeLast();
        classes.pop();
        //else throw new Exception();
   }

    public OWLClass getInitialClass(){
        return source;
    }

    public OWLClass getLastClass(){
        return classes.peek();
    }

    @Override
    public Path clone(){
        Path clone = new Path(onto, source);
        for (PairOfPath pairOfPath : path) {
            clone.addNode(pairOfPath);
        }
        return clone;
    }

    @Override
    public String toString(){
        String ret = source.toString();
        for (PairOfPath pairOfPath : path) {
            ret= ret+" "+pairOfPath.toString();
        }
        return ret;
    }
}